package org.gh.blackcloud.task;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

import org.gh.blackcloud.RemoteStore;
import org.gh.blackcloud.upload.Uploader;

/**
 * 上传任务
 * @author ZhangDi
 *
 */
public class UploadTask implements Runnable {

	private Uploader uploader;
	private String localUrl;
	private RemoteStore remoteStore;
	
	public void run() {
		InputStream in = null;
		String filePath = localUrl;
		try {
			in = new FileInputStream(filePath);
			String remoteUrl = uploader.up(in);
			remoteStore.put(localUrl, remoteUrl);
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} finally {
			if (in != null) {
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}

	public void setUploader(Uploader uploader) {
		this.uploader = uploader;
	}

	public void setLocalUrl(String localUrl) {
		this.localUrl = localUrl;
	}

}
